package com.lyhengtongwl.zqsnews.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ImRezUtils {
    private static Bitmap bm = null;

    public static Bitmap getBitmap(String path) {
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 2;
            bm = BitmapFactory.decodeFile(path, options);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bm;
    }

    /**
     * 把batmap 转file
     *
     * @param bitmap
     * @param filepath
     */
    public static File saveBitmapFile(Bitmap bitmap, String filepath) {
        File file = new File(filepath);//将要保存图片的路径
        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }




    public static Bitmap getBitmap(Bitmap bit) {
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();

            options.inSampleSize = 2;

            bm = BitmapFactory.decodeFile(Environment

                    .getExternalStorageDirectory().getAbsolutePath()

                    + "File.separator + pintuan"+"test.jpg", options);
////            Matrix matrix = new Matrix();
////
////            matrix.setScale(0.5f, 0.5f);
////
////            bm = Bitmap.createBitmap(bit, 0, 0, bit.getWidth(),
////
////                    bit.getHeight(), matrix, true);
//            bm = Bitmap.createScaledBitmap(bit, 150, 150, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bm;
    }
}
